package pub.tbc.toolkit.http;

import com.google.common.collect.Lists;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import pub.tbc.toolkit.Loops;
import pub.tbc.toolkit.function.BiConsumer;

import java.util.List;
import java.util.Map;

/**
 * @author tbc on 2016/8/29 17:29:05.
 */
public class HttpUtil {

    public static final String CONTENT_TYPE_JSON = "application/json";
    public static final String CONTENT_TYPE_FORM = "application/x-www-form-urlencoded";

    public static List<NameValuePair> mapToNamValue2(Map<String, Object> param) {
        final List<NameValuePair> list = Lists.newArrayList();
        Loops.forEach(param, new BiConsumer<String, Object>() {
            @Override
            public void accept(String s, Object o) {
                list.add(new BasicNameValuePair(s, o.toString()));
            }
        });
        return list;
    }

    public static List<NameValuePair> mapToNamValue(Map<String, String> param) {
        final List<NameValuePair> list = Lists.newArrayList();
        Loops.forEach(param, new BiConsumer<String, String>() {
            @Override
            public void accept(String s, String o) {
                list.add(new BasicNameValuePair(s, o));
            }
        });
        return list;
    }
}
